package j2024.j202409;

import java.util.Arrays;
import java.util.Scanner;

public class j0929 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            long a = in.nextLong(),b = in.nextLong();
            if(isv(a) && isv(b)){
                System.out.println("YES");
            }else {
                System.out.println("NO");
            }
        }
    }
    public static boolean isv(long a){
        if(a==1){
            return true;
        }
        if(a==2 || a==3){
            return false;
        }
        for (int i = 2,j=3; i <= a/2; i+=2,j+=2) {
            if(a%i==0){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),k = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int left = 0,right = 0;
        int ret = 0;
        while(right<n){
            while (arr[right]-arr[left]>k){
                left++;
            }
            ret = Math.max(ret,right-left);
            right++;
        }
        System.out.println(ret);

    }
}
